# 聊天窗口发消息

from BasePage import BasePage
from time import sleep


class ChatPage(BasePage):

    _xiaoxiTab = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout[3]/android.widget.RelativeLayout/android.widget.ImageView")
    _xinyonghu = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[4]/android.widget.RelativeLayout")
    # _xinyonghu = (BasePage.XPATH, "//*[@text='感情丰富的猕猴桃']")
    _fanyiChoice = (BasePage.ID, "com.zoneyet.gaga:id/btn_translate")
    _noFanyi = (BasePage.ID, "com.zoneyet.gaga:id/btn_no_need_translate")
    _wenbenContent = (BasePage.ID, "com.zoneyet.gaga:id/et_input")
    _biaoqingButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[5]")
    _biaoqing1 = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.GridView/android.widget.LinearLayout[3]")
    _biaoqing2 = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.GridView/android.widget.LinearLayout[17]")
    _txtSendButton = (BasePage.ID, "com.zoneyet.gaga:id/iv_send")
    _tupianButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.ImageView")
    _xuantuButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[6]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.Button")
    _xuantuCompete = (BasePage.ID, "com.zoneyet.gaga:id/send")
    _xuantuSend = (BasePage.ID, "com.zoneyet.gaga:id/zoneyet_tv_send")
    _paizhaoButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[3]/android.widget.LinearLayout")
    _paisheButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.View")
    _redpacketButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[4]/android.widget.LinearLayout")
    _zidingyiRedpacket = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout[3]/android.widget.TextView")
    _redpacketMoney = (BasePage.ID, "com.zoneyet.gaga:id/chat_send_envelope_price_2")
    _redpacketSend = (BasePage.ID, "com.zoneyet.gaga:id/chat_tv_send_envelope_match_money_in")
    _more = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[6]")
    _giftButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[6]/android.widget.LinearLayout")
    _giftChoice = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.widget.ScrollView/android.widget.LinearLayout/android.widget.GridView/android.widget.LinearLayout[2]/android.widget.RelativeLayout")
    _giftSend = (BasePage.ID, "com.zoneyet.gaga:id/btn_send")
    _cardButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[7]/android.widget.LinearLayout")
    _cardChoice = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.widget.GridView/android.widget.LinearLayout[1]")
    _cardSure = (BasePage.ID, "com.zoneyet.gaga:id/tv_positive_button")
    _fanyiTypes = ["id/btn_no_need_translate", "id/btn_languge_1", "id/btn_languge_2", "id/btn_languge_3", "id/btn_languge_4", "id/btn_languge_5", "id/btn_languge_6", "id/btn_languge_7", "id/btn_languge_8"]
    _yuzhong = []
    _yuyinButton = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.ImageView")
    _yuyinChangan = "com.zoneyet.gaga:id/iv_voice"
    # 再次翻译
    _lastetTxt="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[5]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.TextView"
    _zaiciFanyi = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[1]")
    _queren = (BasePage.ID, "com.zoneyet.gaga:id/ok")
    # 转发
    _zhuanfa = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[2]")
    _xuanren = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[2]")
    _quedingBu = (BasePage.ID, "com.zoneyet.gaga:id/tv_positive_button")
    # 多选
    _duoxuan = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[4]")
    _quxiao = (BasePage.ID, "com.zoneyet.gaga:id/cancel")
    # 删除
    _shanchun = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[3]")
    _queding = (BasePage.ID, "com.zoneyet.gaga:id/tv_dialog_confirm")
    # 设置
    _shezhiButton = (BasePage.ID, "com.zoneyet.gaga:id/iv_title_right")
    _zhiding = (BasePage.ID, "com.zoneyet.gaga:id/iv_chat_config_top")
    _pingbi = (BasePage.ID, "com.zoneyet.gaga:id/iv_chat_config_blacklist")
    _jubao = (BasePage.ID, "com.zoneyet.gaga:id/tv_chat_config_report")
    _jubaoyuanyin = (BasePage.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/androidx.appcompat.widget.LinearLayoutCompat/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[8]")
    _jubaotijiao = (BasePage.ID, "com.zoneyet.gaga:id/tv_report_submit")
    _qingkong = (BasePage.ID, "com.zoneyet.gaga:id/tv_chat_config_clear_history")
    _qingkongqueren = (BasePage.ID, "com.zoneyet.gaga:id/tv_dialog_confirm")

    def new_sendwenben(self):
        # 发各种文本消息+表情
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        for index, value in enumerate(self._fanyiTypes):
            self.click(self._fanyiChoice)
            self._yuzhong = (BasePage.ID, "com.zoneyet.gaga:{i}".format(i=value))
            # print(self._yuzhong)
            self.click(self._yuzhong)
            self.send_keys(self._wenbenContent, "第{order}条消息".format(order=index))
            # na = (self._wenbenContent, "第{order}条消息".format(order=index))
            # print(na)
            self.click(self._biaoqingButton)
            self.click(self._biaoqing1)
            self.click(self._biaoqing2)
            self.click(self._txtSendButton)

    def chat_actions(self):
        _keeptime = 5000
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        # 长按,翻译
        sleep(3)
        self.long_press_xpath(_keeptime)
        self.click(self._zaiciFanyi)
        self.click(self._queren)
        print("再次翻译成功")
        # 长按,转发
        self.long_press_xpath(_keeptime)
        self.click(self._zhuanfa)
        self.click(self._xuanren)
        sleep(3)
        self.click(self._quedingBu)
        sleep(3)
        print("转发成功")
        # 长按，多选
        self.long_press_xpath(_keeptime)
        self.click(self._duoxuan)
        self.click(self._quxiao)
        print("多选成功")
        # 长按，删除
        self.long_press_xpath(_keeptime)
        self.click(self._shanchun)
        self.click(self._queding)
        print("消息删除成功")
        # 设置-聊天置顶
        self.click(self._shezhiButton)
        self.click(self._zhiding)
        print("聊天置顶成功")
        # 设置-屏蔽
        self.click(self._pingbi)
        self.click(self._pingbi)
        print("聊天屏蔽成功")
        # 设置-举报
        self.click(self._jubao)
        self.click(self._jubaoyuanyin)
        self.swipe_up()
        self.click(self._jubaotijiao)
        print("聊天举报成功")
        # 设置-清空聊天记录
        self.click(self._qingkong)
        self.click(self._qingkongqueren)
        print("聊天清空成功")

    def send_album(self):
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        sleep(3)
        # 发窗口图
        self.click(self._tupianButton)
        self.click(self._xuantuButton)
        self.click(self._xuantuCompete)
        sleep(3)
        self.click(self._xuantuSend)

    def send_photo(self):
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        sleep(3)
        # 拍照发图
        self.click(self._paizhaoButton)
        self.click(self._paisheButton)
        self.click(self._xuantuSend)

    def send_redpacket(self):
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        sleep(3)
        # 发自定义红包
        self.click(self._redpacketButton)
        self.click(self._zidingyiRedpacket)
        self.send_keys(self._redpacketMoney, "1")
        self.hide_keyboard()
        # self.click(self._redpacketSend)

    def send_gift(self):
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        sleep(3)
        # 发礼物
        self.click(self._more)
        self.click(self._giftButton)
        self.click(self._giftChoice)
        self.click(self._giftSend)

    def send_card(self):
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        sleep(3)
        # 发名片
        self.click(self._more)
        self.click(self._cardButton)
        self.click(self._cardChoice)
        self.click(self._cardSure)

    def send_yuyin(self):
        _keeptime = 5000
        self.click(self._xiaoxiTab)
        self.click(self._xinyonghu)
        sleep(3)
        # 发名片
        self.click(self._yuyinButton)
        self.long_press(self._yuyinChangan, _keeptime)

